#include "StdAfx.h"
#include "MyD3DSystem.h"

#pragma comment ( lib, "d3d9.lib" )
#pragma comment ( lib, "d3dx9.lib" )

CMyD3DSystem::CMyD3DSystem(void)
{
	m_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
}

CMyD3DSystem::~CMyD3DSystem(void)
{
}


HRESULT CMyD3DSystem::InitD3D(HWND hWnd)
{
	
	if (NULL == m_pD3D)
	{
		MessageBox(NULL,_T("CreateD3D false"),NULL,MB_OK);
		return S_FALSE;
	}
	D3DPRESENT_PARAMETERS D3Dpp;
	ZeroMemory(&D3Dpp,sizeof(D3Dpp));
	D3Dpp.Windowed = TRUE;
	D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	D3Dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	//if (D3DERR_INVALIDCALL == m_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,
	//	D3DCREATE_SOFTWARE_VERTEXPROCESSING,&D3Dpp,&m_pD3DDevice ))
	//{
	//	MessageBox(NULL,_T("bingo"),NULL,MB_OK);
	//}

	if (D3D_OK != m_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,&D3Dpp,&m_pD3DDevice ))
	{
		MessageBox(NULL,_T("CreateD3D Device false"),NULL,MB_OK);
		return S_FALSE;
	}

	return S_OK;

}

void CMyD3DSystem::ClearUp()
{
	m_pD3D->Release();
	m_pD3DDevice->Release();
}

LPDIRECT3D9 CMyD3DSystem::GetD3DSys()
{
	return m_pD3D;
}
LPDIRECT3DDEVICE9 CMyD3DSystem::GetD3DDevice()
{
	return m_pD3DDevice;
}